package com.wc.alorithm_blue_bridge._数据结构.tire.Q9491;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * @Author congege
 * @Description 数对统计
 * https://www.lanqiao.cn/problems/9491/learning/?contest_id=153
 * @Date Created in 2023/12/9-22:28
 */
public class Main {
    static int maxN = (int) 1e6 + 10;
    static int[] array = new int[maxN];
    static int[][] tree = new int[maxN * 20][2];
    static int[] cnt = new int[maxN * 20];
    static int idx = 1;

    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    public static void main(String[] args) {
        int n = nextInt();
        for (int i = 1; i <= n; i++) {
            array[i] = nextInt();
            add(1, array[i]);
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            ans += queryAns(1, array[i], 19);
        }
        System.out.println(ans);
    }

    public static int nextInt() {
        try {
            in.nextToken();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return (int) in.nval;
    }

    public static void add(int p, int val) {
        for (int i = 19; i >= 0; i--) {
            int u = (val >> i & 1);
            if (tree[p][u] == 0) {
                tree[p][u] = ++idx;
            }
            p = tree[p][u];
        }
        ++cnt[p];
    }

    public static int queryAns(int p, int val, int dit) {
        int u = val >> dit & 1;
        if (dit == 0) {
            if (u == 0) {
                return cnt[tree[p][0]] + cnt[tree[p][1]];
            } else {
                return cnt[tree[p][0]];
            }
        }
        int ans = 0;

        if (tree[p][0] != 0) {
            ans += queryAns(tree[p][0], val, dit - 1);
        }
        if (tree[p][1] != 0) {
            if (u == 0) {
                ans += queryAns(tree[p][1], val, dit - 1);
            }
        }

        return ans;
    }
}
